<template>
    <div class="login-container">
        <div class="form-box">
            <a-form
                id="components-form-demo-normal-login"
                :form="form"
                class="login-form"
                @submit="handleSubmit"
            >
                <a-form-item>
                    <a-input
                        v-decorator="[
                            'userName',
                            {
                                initialValue: 'admin',
                                rules: [
                                    {
                                        required: true,
                                        message: '请输入用户名!',
                                    },
                                ],
                            },
                        ]"
                        size="large"
                        placeholder="用户名"
                    >
                        <a-icon
                            slot="prefix"
                            type="user"
                            style="color: rgba(0, 0, 0, 0.25)"
                        />
                    </a-input>
                </a-form-item>
                <a-form-item>
                    <a-input
                        v-decorator="[
                            'password',
                            {
                                initialValue: 123456,
                                rules: [
                                    {
                                        required: true,
                                        message: '请输入密码!',
                                    },
                                ],
                            },
                        ]"
                        size="large"
                        type="password"
                        placeholder="密码"
                    >
                        <a-icon
                            slot="prefix"
                            type="lock"
                            style="color: rgba(0, 0, 0, 0.25)"
                        />
                    </a-input>
                </a-form-item>
                <a-form-item>
                    <ARow>
                        <ACol :span="8">
                            <a-checkbox
                                v-decorator="[
                                    'remember',
                                    {
                                        valuePropName: 'checked',
                                        initialValue: true,
                                    },
                                ]"
                            >
                                <span class="remember">Remember me</span>
                            </a-checkbox>
                        </ACol>
                        <a-col :span="8" :offset="8">
                            <span class="forgot"> Forgot password </span>
                        </a-col>
                    </ARow>
                    <a-button
                        size="large"
                        type="primary"
                        html-type="submit"
                        :loading="loading"
                        class="login-form-button"
                    >
                        登录
                    </a-button>
                    <span class="register">register now!</span>
                </a-form-item>
            </a-form>
        </div>
    </div>
</template>

<script>
import { mapActions } from "vuex";
import { settingConfig, appConfig } from "@/config";
import { JSEncrypt } from "jsencrypt";
const verify = new JSEncrypt();
verify.setPublicKey(appConfig.encryPublicKey);
import { ssoLogin } from "@/sso";
export default {
    data() {
        return {
            loading: false,
        };
    },
    beforeCreate() {
        this.form = this.$form.createForm(this);
    },
    created() {
        // ssoLogin(this.$router);
    },
    methods: {
        ...mapActions("user", ["loginHandler"]),
        handleSubmit(e) {
            e.preventDefault();
            this.form.validateFields((err, values) => {
                if (err) return;
                this.loading = true;
                values.password = verify.encrypt(values.password);
                this.loginHandler(values).then(() => {
                    this.$message.success("登录成功");
                    this.$router.push({
                        name: settingConfig.homeName,
                    });
                    this.loading = false;
                });
            });
        },
    },
};
</script>
<style lang="less" scoped>
.login-container {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: url("../../assets/login/login2.jpg") no-repeat;
    background-size: 100% 100%;
    .form-box {
        width: 36%;
        height: 50vh;
        display: flex;
        align-items: center;
        justify-content: center;
        padding-top: 4%;
        background: url("../../assets/login/bg_login_form.png") no-repeat;
        background-size: 100% 100%;
        .register,
        .forgot,
        .remember {
            color: #fff;
        }
    }
    .login-form {
        width: 70%;
    }
}

#components-form-demo-normal-login .login-form-button {
    width: 100%;
}
</style>
